from db import DB
from db_base import Users as DBUser
from db_base import Oplogs
from pprint import pprint


class Admin():
    def __init__(self):
        self.db = DB()

    def view_op(self):
        results = []
        result_sets = self.db.session.query(Oplogs)
        for record in result_sets:
            results.append([record.id, record.nickname, record.time, record.op, record.result])
        return results

    def view_op_by_user(self, nickname):
        results = []
        result_sets = self.db.session.query(Oplogs).filter(Oplogs.nickname.in_([nickname]))
        for record in result_sets:
            results.append([record.id, record.nickname, record.time, record.op, record.result])
        return results

    def view_user(self):
        results = []
        result_sets = self.db.session.query(DBUser)
        for record in result_sets:
            results.append([record.nickname, record.password, record.gender, record.age, record.is_online])
        return results


if __name__ == '__main__':
    a = Admin()
    pprint(a.view_op())
    pprint(a.view_user())
    pprint(a.view_op_by_user('123'))
